Repository navigation
drm/apple: v26 link: fix READY/callback race, pump busy-spin, and NULL buffer deref - #4777
RyanTheTide wants to merge 1 commit into
Conversation
…L buffer deref Fix four transport bugs in the J613/25G83 DCPLink RPC implementation: 1. Handshake READY-to-callback race and pre-alloc receive handling: dcp_v26_link_receive() previously set ready_result = 0 and completed link->ready without setting link->enabled = true under link->lock. Any firmware callback arriving before dcp_v26_link_start() woke and acquired link->lock re-entered the !link->enabled path, overwrote ready_result with -EPROTO, dropped the callback, and killed the link. Conversely, a malformed ready message did not fail the link, allowing a subsequent READY message to overwrite -EPROTO with 0. Also ignore messages arriving while link->rpc is NULL, and publish/clear link->rpc under link->lock. 2. Pump failure orphan / 5-second CPU busy-spin: When link_callback() failed in dcp_v26_link_pump(), the event was freed without removing the callback entry or failing the link. Any later dcp_v26_link_call() saw event_count == 0 and callback_count > 0, causing link_submit() to return -EBUSY and retry in a tight busy-spin for the entire 5-second call timeout. Fail the link when dcp_v26_link_pump() fails a callback, and only retry -EBUSY when event_count is non-zero. 3. NULL input/output buffer dereference in dcp_v26_link_call(): Reject non-zero input_size/output_size with a NULL pointer before copying into or out of the RPC packet. 4. Overflow-safe bounds check and checked message encoding in link_submit(): Avoid offset + size addition overflow and validate apple_dcp_link_rpc_message() / apple_dcp_link_stream_message() return values before mutating link->rpc or link->calls[nested]. Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
|
Core review at Checked
Pending CI completion + exact-head hardware row (will batch into the next kernel cloud-build once |
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
satchlj
left a comment
There was a problem hiding this comment.
Reviewed at 6dc156be3bcc: setting link->enabled = true under link->lock inside dcp_v26_link_receive() upon DCP_V26_LINK_READY_MSG closes the READY-vs-first-callback race cleanly while preserving -EPROTO on unexpected handshake messages; checking apple_dcp_link_{rpc,stream}_message() errors and overflow-safe layout.capacity bounds before writing shared RPC memory prevents partial submits; dcp_v26_link_pump() fails the link on callback errors; and dcp_v26_link_call() guards NULL non-zero buffers and gates -EBUSY retries on READ_ONCE(link->event_count) to avoid busy-spinning. Code-review only (not tested on hardware).
There was a problem hiding this comment.
Verdict: MERGE at 6dc156b
Checked:
- Full adversarial audit of
drivers/gpu/drm/apple/iomfb_v26_6_link.cand the 4 new KUnit tests at6dc156be3bcc:dcp_v26_link_receive()executes on the RTKit ordered workqueue (valid mutex/GFP_KERNEL),dcp_v26_link_start()publishesrpc/rpc_dva/enabled/ready_resultunderlink->lockand clears under lock on error, pump-EBUSYloop bounds retry without busy-spinning or missed wakeups, NULL non-zero buffers are rejected cleanly while valid zero-length calls remain allowed, and layout capacity arithmetic is overflow-checked. - DCO and
pr-textclean; no SoC/board gates. Pending CI + exact-head hardware row.
|
Hardware check (batched exact-head trial on
|
What: Fix four transport bugs in the J613/25G83 DCPLink RPC implementation (
drivers/gpu/drm/apple/iomfb_v26_6_link.c): an atomic handshake race betweenREADYand immediate firmware callbacks (plus pre-allocation receive guards), an orphaned callback entry after a faileddcp_v26_link_pump()that caused a 5-second 100% CPU busy-spin indcp_v26_link_call(), NULL input/output buffer dereferences indcp_v26_link_call(), and overflow/unchecked message encoding inlink_submit().Tested: ARM64 QEMU KUnit (
dcp-v26-link, 9/9 passed under both-smp 2and-smp 1withpanic_on_warn=1,KASAN,UBSAN,PROVE_LOCKING,FORTIFY_SOURCE,WERROR),W=1 C=1 KCFLAGS="-Wshadow"withKUNIT=yandKUNIT=n, mixedDRM_APPLE=y+KUNIT=mbuild,scripts/kernel-doc -Wall -none, andscripts/checkpatch.pl --strict --git origin/main..HEAD(0 errors, 0 warnings, 0 checks). Negative-control KUnit runs on unmodifiedorigin/mainreproduced all four defects (including the 5000 ms busy-spin and KASAN NULL pointer dereference panic).Risk: two-way · scoped to
drivers/gpu/drm/apple/iomfb_v26_6_link.cand its KUnit suite (iomfb_v26_6_link_test.c); cleanly revertible withgit revert 6dc156be3bcc.Not yet: On-device hardware validation row on a J613/25G83 DCP target (queued in
HWROWS-QUEUE.md).Details
READY-to-callback race and pre-alloc receive safety (
dcp_v26_link_start,dcp_v26_link_receive):dcp_v26_link_receive()previously setlink->ready_result = 0and calledcomplete(&link->ready)without settinglink->enabled = trueunderlink->lock. Any firmware callback arriving beforedcp_v26_link_start()woke and acquiredlink->lockhit the!link->enabledbranch, overwroteready_resultwith-EPROTO, dropped the callback, and killed the link.READYbeforedcp_v26_link_start()woke overwrote-EPROTOwith0.dcp_v26_link_receive()now ignores messages while!link->rpc, atomically setslink->enabled = trueonDCP_V26_LINK_READY_MSG, and callslink_fail(link)on a bad handshake message.dcp_v26_link_start()publishes and clearslink->rpcunderlink->lock, preserves-EPROTOon bad handshake, and clearslink->enabledon failure/timeout.Pump failure orphan and 5-second busy-spin (
dcp_v26_link_pump,dcp_v26_link_call):link_callback()failed indcp_v26_link_pump(), the dequeued event was freed without failing the link or clearinglink->callbacks[], leavingevent_count == 0withcallback_count > 0. Subsequentdcp_v26_link_call()calls retried-EBUSYin a tight loop for the full 5-secondDCP_V26_CALL_TIMEOUT.dcp_v26_link_pump()now fails the link onlink_callback()error (an unanswered firmware callback wedges firmware), anddcp_v26_link_call()only retries-EBUSYwhenREAD_ONCE(link->event_count)is non-zero.NULL buffer dereferences (
dcp_v26_link_call):(input_size && !input) || (output_size && !output)with-EINVALbeforememcpy().Overflow-safe capacity check and message encoding validation (
link_submit):offset + size > layout.capacitywithoffset > layout.capacity || size > layout.capacity - offset, and checkapple_dcp_link_rpc_message()/apple_dcp_link_stream_message()return values before mutatinglink->rpcorlink->calls[nested].Evidence
Negative controls on unmodified
origin/main(184d0e40c216)Post-fix verification (
6dc156be3bcc8cd45bafdcb22244471614628e4e)-smp 2,panic_on_warn=1,KASAN,UBSAN,PROVE_LOCKING,FORTIFY_SOURCE,WERROR):Testing complete. Ran 9 tests: passed: 9-smp 1,panic_on_warn=1):Testing complete. Ran 9 tests: passed: 9ARCH=arm64 LLVM=1 W=1 C=1 KCFLAGS="-Wshadow"(KUNIT=yandKUNIT=n): 0 warnings in modified code (only pre-existing upstreaminclude/linux/wait.h:306explicit shadow inwait_event_timeout)DRM_APPLE=y,KUNIT=m,DRM_APPLE_KUNIT_TEST=m): builds cleanly with zero modularkunit.kosymbol referencesscripts/kernel-doc -Wall -none: 0 warningsscripts/checkpatch.pl --strict --git origin/main..HEAD:total: 0 errors, 0 warnings, 0 checks, 315 lines checked